class Solution
{
public:
    int removeCoveredIntervals(vector<vector<int>> &intervals)
    {
        sort(intervals.begin(), intervals.end(), IntervalComparator());
        int n = intervals.size();
        int count = 0;
        for (int i = 0; i < n; ++i)
        {
            if (intervals[i][0] == -1)
            {
                continue;
            }
            else
            {
                ++count;
            }
            for (int j = i + 1; j < n; ++j)
            {
                if (intervals[i][1] >= intervals[j][1])
                {
                    intervals[j][0] = -1;
                }
            }
        }
        return count;
    }

private:
    // 按照左端点升序，右端点降序排序，后续逻辑简单一些
    class IntervalComparator
    {
    public:
        bool operator()(const vector<int> &left, const vector<int> &right)
        {
            if (left[0] != right[0])
            {
                return left[0] < right[0];
            }
            return right[1] < left[1];
        }
    };
};